package com.itcast.n1_内存调优;

import java.util.ArrayList;

/**
 * @program: jvm
 * @description:
 * @author: flyduck
 * @create: 2024-10-16 16:02
 **/
public class Test06_内存泄漏问题2_非静态内部类会持有外部类导致内存泄漏 {
    public static void main(String[] args) throws InterruptedException {
        int count = 0;
        ArrayList<Outer3.Inner3> inner3s = new ArrayList<>();
        while (true) {
            if(count++ % 100 == 0){
                Thread.sleep(10);
            }
            inner3s.add(new Outer3().new Inner3());
        }
    }
}

class Outer3 {
    private byte[] bytes = new byte[1024]; //外部类持有数据
    private static String name  = "测试";
    class Inner3 {
        private String name;
        public Inner3() {
        }
    }
}
